package cn.iocoder.yudao.module.locale.controller.app.tabledata;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.locale.controller.app.tabledata.vo.AppTableDataConditionRespVO;
import cn.iocoder.yudao.module.locale.controller.app.tabledata.vo.AppTableDataRespVO;
import cn.iocoder.yudao.module.locale.controller.app.tabledata.vo.TableDataConditionReqVO;
import cn.iocoder.yudao.module.locale.convert.tabledata.TableDataConverter;
import cn.iocoder.yudao.module.locale.dal.dataobject.tabledata.TableDataDO;
import cn.iocoder.yudao.module.locale.service.tabledata.TableDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 表数据国际化")
@RestController
@RequestMapping("/locale/table-data")
@Validated
public class AppTableDataController {

    @Resource
    private TableDataService tableDataService;

    @GetMapping("/get")
    @Operation(summary = "获得表数据国际化")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppTableDataRespVO> getTableData(@RequestParam("id") Long id) {
        TableDataDO tableData = tableDataService.getTableData(id);
        return success(BeanUtils.toBean(tableData, AppTableDataRespVO.class));
    }

    @PostMapping("/list-by-condition")
    @Operation(summary = "获得表数据国际化（基于条件）")
    public CommonResult<AppTableDataConditionRespVO> getTableData(@Valid @RequestBody TableDataConditionReqVO conditionVO) {
        final List<TableDataDO> dataDOList = tableDataService.selectList(conditionVO);
        final AppTableDataConditionRespVO respVO = TableDataConverter.convertToRespVO(dataDOList);
        return success(respVO);
    }

}